package backend.service.admin;

import backend.model.admin.Activity;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityServiceImpl extends DBModelServiceImpl<Activity> implements ActivityService {

    @Override
    public Class<Activity> getEntityClass() {
        return Activity.class;
    }

    @Override
    public List<Activity> findAllActivities() {
        return dbModelDao.findByNamedQuery("findAllActivities");
    }

    @Override
    public List<Activity> findAllActiveActivities() {
        return dbModelDao.findByNamedQuery("findAllActiveActivities");
    }

    @Override
    public Activity findActivityByName(String name) {
        List<Activity> activitiesByName = dbModelDao.findByNamedQueryAndParams("findActivityByName", new String[]{"name"}, new Object[]{name});
        assert activitiesByName.size() <= 1;
        if (activitiesByName.size() == 1) {
            return activitiesByName.get(0);
        }
        return null;
    }
}
